package com.yuerlive.rainbow.module.mine.presenter;

import com.yuerlive.rainbow.api.EditApi;
import com.yuerlive.rainbow.api.EditService;
import com.yuerlive.rainbow.base.BasePresenterImpl;
import com.yuerlive.rainbow.entity.BaseData;
import com.yuerlive.rainbow.entity.EditedInfo;
import com.yuerlive.rainbow.entity.User;
import com.yuerlive.rainbow.rx.RxHelper;
import com.yuerlive.rainbow.rx.RxObserver;
import com.yuerlive.rainbow.utils.ToastUtils;
import com.yuerlive.rainbow.utils.UserProxy;
import com.yuerlive.rainbow.widget.timeselector.TextUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Admin on 2017/6/1.
 */

public class EditPresenter extends BasePresenterImpl implements EditContract.Presenter {
    private EditContract.View view;
    private EditService service;
    public EditPresenter(EditContract.View view) {
        this.view=view;
        view.setPresenter(this);
        this.service= EditApi.getInstance().service;
    }

    @Override
    public void getEditRequest(EditedInfo info) {
        User user = UserProxy.getUser();
        Map<String,String> params =new HashMap<>();
        if(!TextUtil.isEmpty(info.getBirthday())){
            params.put("birthday",info.getBirthday());
        }
        if(!TextUtil.isEmpty(info.getMobile())){
            params.put("mobile",info.getMobile());
        }
        if(!TextUtil.isEmpty(info.getIcon())){
            params.put("icon",info.getIcon());
        }
        if(!TextUtil.isEmpty(info.getNickname())){
            params.put("nickname",info.getNickname());
        }
        if(!TextUtil.isEmpty(info.getPersonsignature())){
            params.put("personsignature",info.getPersonsignature());
        }
        if(!TextUtil.isEmpty(info.getSex())){
            params.put("sex",info.getSex());
        }

       service.getEditRequest(params).compose(RxHelper.toUI()).subscribe(new RxObserver<BaseData>(this) {
           @Override
           protected void onSuccess(BaseData baseData) {
               view.showResutl(baseData,info.getType());
           }

           @Override
           protected void onFail(String message) {

           }
       });
    }
}
